<?php
$servername = "localhost";
$username = "root";
$password = "";
$dbname = "myDB";

$con=mysqli_connect($servername, $username, $password, $dbname);
// 检测连接
if (mysqli_connect_errno())
{
    echo "连接失败: " . mysqli_connect_error();
}

$result = mysqli_query($con,"SELECT * FROM Persons ORDER BY age");
/*
 报错 Warning: mysqli_fetch_array() expects parameter 1 to be mysqli_result, boolean given in /Users/leiyan/Sites/Document/MySQL/MySQLi/MySQLi_orderBy.php on line 17
 实际上是sql语句问题，并不存在 Persons表。
*/
$result = mysqli_query($con, "select * from MyGuests order by email");

//应该加上判断，防止sql语句错误
if (!$result) {
    die('order fail: ' . mysqli_error($con));
}

while($row = mysqli_fetch_array($result))
{
    //输出不对
//     echo $row['FirstName'];
//     echo " " . $row['LastName'];
//     echo " " . $row['Age'];
    echo $row[1];
    echo " " . $row[2];
    echo " " . $row[3];
    echo "<br>";
}

mysqli_close($con);
?>